package com.dongbo.recorder.screenrecord.dialog;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

import com.dongbo.recorder.screenrecord.R;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class PayDialog extends Dialog {

    private OnDialogEventListener onDialogEventListener;
    private Context context;

    /**
     * @param context
     * @param themeResId
     * @param onDialogEventListener dialog 事件回调
     */
    public PayDialog(Context context,
                     int themeResId,
                     PayDialog.OnDialogEventListener onDialogEventListener) {
        super(context, themeResId);
        this.context = context;
        this.onDialogEventListener = onDialogEventListener;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_dialog_pay);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.tv_weixin,
            R.id.tv_alipay,})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_weixin:
                if (onDialogEventListener != null) {
                    onDialogEventListener.onWx();
                }
                dismiss();
                break;
            case R.id.tv_alipay:
                if (onDialogEventListener != null) {
                    onDialogEventListener.onAlipay();
                }
                dismiss();
                break;
        }
    }

    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.BOTTOM;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
//        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }


    public interface OnDialogEventListener {

        void onWx();

        void onAlipay();
    }

    public void destroy() {
        onDialogEventListener = null;
        context = null;
        dismiss();
        cancel();
    }

}